/*
 * @Author: your name
 * @Date: 2021-10-19 16:29:50
 * @LastEditTime: 2021-10-26 14:15:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wx-x-mai\pages\workService\gxuniversity\firstpage\index.js
 */
/**
 * @see
 */
const app = getApp()
import {
  getXnxqListGxdx
} from '../../../../utils/util'


const xnxqList = getXnxqListGxdx()
Page({
  data: {
    showPic1: false,
    showPic2: false,
    showPic3: false,
    showPic5: false,
    appMsg: {
      type: '', // 状态
      show: false, // 是否展示
    },
    errinfo: "",
    currentindex: 0,
    currentindexdata: 0,
    historyList: [],
    courseList: [],
    courseListitem: [],
    chooseCourseAnalyzeData: [],
    index: xnxqList.length - 1,
    xnxqList,
    imageUrl: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg.png',
    imageUrlbg3: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg3.png',
    imageUrlbg4: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg4.png',
    imageUrlbg5: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg5.png',
    imageUrlbg6: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg6.png',
    imageUrlbg7: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg7.png',
    imageUrlbg8: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg8.png',
    imageUrlbg9: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg9.png',
    Image: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/dialogbg1.png',
    bgcenter: "https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg-center.png",
    indicatorDots: true,
    current: '',
    paramsdata: {},
    vertical: false,
    autoplay: false,
    autoplayitems: false,
    autoplaydata: true,
    durationitems: 500,
    reportScoreSubject: [],
    creditStatics: [],
    interval: 2000,
    intervaldata: 2000,
    intervalitems: 500,
    durationdata: 500,
    duration: 500,
    courseName: "",
    score: "",
    beginSchoolYear: "",
    endSchoolYear: "",
  },
  onLoad(options) {
    this.setData({
      beginSchoolYear: options.beginSchoolYear,
      endSchoolYear: options.endSchoolYear
    })
    this.reportTermget();
  },

  /**
   * @see 点击选择下拉学年学期
   */
  bindPickerChange(e) {
    this.setData({
      index: e.detail.value,
    })
    this.reportTermget();
  },
  confirmPop() {
    this.setData({
      showPic1: false,
      current: null,
      courseListitem: [],
      courseList: [],
    })
  },

  confirmPop5() {
    this.setData({
      showPic5: false,
      errinfo: "",
    })
  },
  cancelPop5() {
    this.setData({
      showPic5: false,
      errinfo: ""
    })
  },
  cancelPop() {
    this.setData({
      showPic1: false,
      current: null,
      courseListitem: [],
      courseList: [],
    })
  },

  confirmPopd() {
    this.setData({
      showPic2: false
    })
  },
  cancelPopd() {
    this.setData({
      showPic2: false
    })
  },


  confirmPopc() {
    this.setData({
      showPic3: false
    })
  },
  cancelPopc() {
    this.setData({
      showPic3: false
    })
  },
  // 必修未获得学分
  bindage(e) {
    if (this.data.paramsdata.reportScoreRuCourseList.length > 0) {
      this.setData({
        showPic1: true
      })
    } else {
      wx.showToast({
        title: '暂无数据',
        icon: 'error',
        duration: 1000
      })

    }

  },
  // 选修
  report() {
    if (this.data.paramsdata.reportScoreOuCourseList.length > 0) {
      this.setData({
        showPic2: true
      })
    } else {
      wx.showToast({
        title: '暂无数据',
        icon: 'error',
        duration: 1000
      })
    }
  },
  // 辅修
  reportScoreMuCourseList() {
    if (this.data.paramsdata.reportScoreMuCourseList.length > 0) {
      this.setData({
        showPic3: true
      })
    } else {
      wx.showToast({
        title: '暂无数据',
        icon: 'error',
        duration: 1000
      })
    }
  },
  reportTermget() {
    const schoolConfig = wx.getStorageSync('schoolConfig')
    const userInfo = wx.getStorageSync('userInfo');
    const request = {
      beginSchoolYear: this.data.beginSchoolYear,
      endSchoolYear: this.data.endSchoolYear,
      // userId: userInfo.userId,
      // schoolCode: schoolConfig.schoolCode
    }
    // this.setData({
    //   appMsg: {
    //     type: 'loading',
    //     show: true,
    //   },
    // })
    wx.showLoading({
      title: '加载中',
    })
    wx.$API['workService/reportTermget'](request).then((result) => {
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
      console.log(result.data, '判断条件')
      if (result.data != null) {
        console.log(result.data, '进来了')
        const courseAnalyzeData = result.data.courseAnalyzeData;
        const chooseCourseAnalyzeData = result.data.chooseCourseAnalyzeData;
        const reportScoreSubject = result.data.reportScoreSubject;
        const creditStatics = result.data.creditStatics;
        var strs = new Array(); //定义一数组
        strs = reportScoreSubject.split(","); //字符分割
        //  reportScoreRank
        this.setData({
          paramsdata: result.data,
          reportScoreSubject: strs,
          historyList: courseAnalyzeData,
          chooseCourseAnalyzeData: chooseCourseAnalyzeData,
          creditStatics: creditStatics
        })
      } else {
        wx.showToast({
          title: '暂无数据',
          icon: 'error',
          duration: 1000
        })
      }


    }).catch((err) => {
      setTimeout(function () {
        wx.navigateBack({
          delta: 0,
        })
      }, 2000)
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)

    })
  },

  clickage(e) {
    const courseList = e.currentTarget.dataset.item;
    if (courseList.length > 0) {
      this.setData({
        courseList: courseList,
        showPic1: true,
        current: 1,
      })
    } else {
      wx.showToast({
        title: '暂无数据',
        icon: 'error',
        duration: 1000
      })
    }

  },

  clickagedata(e) {
    const courseListdata = e.currentTarget.dataset.item.courseList;
    if (courseListdata.length > 0) {
      this.setData({
        courseListitem: courseListdata,
        showPic1: true,
        current: 2,
      })
    } else {
      wx.showToast({
        title: '暂无数据',
        icon: 'error',
        duration: 1000
      })
    }
  },

  changecrrent(e) {
    this.setData({
      currentindex: e.detail.current
    })
  },

  changecrrentdata(e) {
    this.setData({
      currentindexdata: e.detail.current
    })
  },



  changeIndicatorDots(e) {
    console.log(e.detail.current)
    this.setData({
      current: e.detail.current
    })
    console.log(this.data.current)
    // this.setData({
    //   indicatorDots: !this.data.indicatorDots
    // })
  },
  onShareTimeline(res) {
    if (this.data.current == 7) {
      return {
        title: '分享成绩单至朋友圈',
        path: 'pages/workService/gxuniversity/twopage/index',
        imageUrl: 'https://xwx.gzzmedu.com:6899/wx-x-mai/123.png'
      }
    }
  },

  comback() {
    wx.switchTab({
      url: '../../../../pages/home/index'
    })
  },
  onShareAppMessage: function (res) {
    console.log(res, '测试分享朋友功能')
    //转发事件来源 ：from （button:页面内按钮分享  menu:右上角转发菜单）
    if (res.from == 'button') { //自定义按钮分享
      //如果form值是button，则target是触发这次转发事件的button，否则为undefined
      //自定义转发内容
      var title = ""
      var path = ""
      var imageUrl = ""
      var jsonStr = {
        id: 1,
        name: "张三"
      }
      if (res.target.dataset.index == 1) { //分享1
        title = "分享1"
        path = "pages/workService/gxuniversity/twopage/index"
        imageUrl = "https://xwx.gzzmedu.com:6899/wx-x-mai/123.png"
      } else if (res.target.dataset.index == 2) { //分享2
        title = "分享2"
        path = "pages/workService/gxuniversity/twopage/index"
        imageUrl = "https://xwx.gzzmedu.com:6899/wx-x-mai/123.png"
      } else if (res.target.dataset.index == 3) { //分享3
        title = "分享3"
        path = "pages/workService/gxuniversity/twopage/index"
        imageUrl = "https://xwx.gzzmedu.com:6899/wx-x-mai/123.png"
      }
      return {
        title: title,
        path: path,
        imageUrl: imageUrl,
        success: function (res) {

          console.log('分享成功')
        },
        fail: function (res) {
          console.log('分享失败')
        }
      }
    } else { //右上角转发菜单
      if (this.data.current == 7) {
        return {
          title: "benye分享",
          path: "pages/workService/gxuniversity/twopage/index",
          imageUrl: "https://xwx.gzzmedu.com:6899/wx-x-mai/123.png",
          success: function (res) {
            console.log('分享成功')
          },
          fail: function (res) {
            console.log('分享失败')
          }
        }
      }

    }
  },
  // onShareAppMessage: function(ops) {
  //   return {
  //     title: "分享卡片",
  //     path: '../test/test',
  //     }
  // },
  getMsgHandle(e) {

  },
  lookdetail() {
    wx.navigateTo({
      url: '../../../schoolStudy/grade/grade'
    })
  }
  // change(e){
  //   debugger;
  // },

  // changeAutoplay() {
  //   this.setData({
  //     autoplay: !this.data.autoplay
  //   })
  // },

  // intervalChange(e) {
  //   this.setData({
  //     interval: e.detail.value
  //   })
  // },

  // durationChange(e) {
  //   this.setData({
  //     duration: e.detail.value
  //   })
  // }

})